/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dp.model;

import com.dp.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author hisik
 */
public class BooksDao extends AbstractDao<Books> implements IBaseDao<Books> {
    
    private static BooksDao booksDao;

    public static BooksDao getInstance() {
        if(booksDao == null)
            booksDao = new BooksDao();
        return booksDao;
    }
    
    public List<Books> getBooksByName(String name) {
        
        List<Books> list = null;
        Session session = null;
        try {
        
            session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();

            Query query = session.createQuery("select b from Books b where b.bookName like :name ");
            query.setParameter("name", "%".concat(name).concat("%"));

            list = (List<Books>)query.list();
            
        } catch (Exception ex) {
            
        } finally {
            if(session != null) {
                session.flush();
                session.close();
            }
        }
        
        return list;
    }
}
